﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<% Html.Telerik().Grid<WiseLink.RDS.Model.DiagnosticModel>()
    .Name("Diagnostic")
    .ToolBar(toolBar => toolBar.Template(() =>
     {
        %>
                     <label>Contact Result:</label>
                     <% Html.Telerik().DropDownList()
                            .Name("contactResultList")
                            .DataBinding(binding => binding.Ajax().Select("GetContactResultList", "Diagnostic"))
                            .DropDownHtmlAttributes(new {style =  "top :7px"})
                            .Render();
                      %>
                      <%= Html.TextBox("contactRemark", null, new { style = "margin-left:10" })%>
                     <button id="btnSaveContactResult" onclick="onSaveContact(this)">Save</button>
         <%
    }))
    .Columns(columns =>
    {
        columns.Bound(o => o.Urgent).Width(100);
        columns.Bound(o => o.Fault).Width(100);
        columns.Bound(o => o.Maintenance).Width(100);
        columns.Bound(o => o.Name).Width(100);
        columns.Bound(o => o.SerialNo).Width(200);
        columns.Bound(o => o.VehicleID).Width(100);
    })
        .DataBinding(dataBinding => dataBinding.Ajax().Select("FirstLook", "Diagnostic"))
    .Pageable()
    .Sortable()
    .Selectable()
    .Filterable()
    .ClientEvents(events => events.OnRowSelect("onRowSelected"))
    .Render();
    %>
    <br />
    <h3>vehicleID= <span id="vehicleID"/> </h3><h3>tabItemID= <span id="tabItemText"/></h3>
     <% Html.Telerik().TabStrip()
            .Name("TabStrip")
            .Items(tabstrip =>
            {
                tabstrip.Add()
                    .Text("Fault")
                    .Content(() =>
                    {
                         Html.Telerik().Grid<WiseLink.RDS.Model.FaultModel>()
                                .Name("VehicleFault")
                                .Columns(columns=>
                                {
                                    columns.Bound(f => f.Code).Width(50);
                                    columns.Bound(f => f.CodeDescription).Width(200);
                                    columns.Bound(f => f.IDCSimNumber).Width(200);
                                    columns.Bound(f => f.HappenDate).Format("{0:MM/dd/yyyy}").Width(120);
                                    columns.Bound(f => f.IsConfirmed).Width(100).Title("Confirmed")
                                            .ClientTemplate("<input type='checkbox' disabled='disabled' name='IsConfirmed' <#= IsConfirmed? checked='checked' : '' #> />");
                                })
                                .DataBinding(dataBinding => dataBinding.Ajax().Select("GetUnConfirmedFaultVehicle", "Diagnostic"))
                                .ClientEvents(clientEvents => clientEvents.OnDataBinding("onDataBinding"))
                                .Pageable()
                                .Sortable()
                                .Render();
                    });
                tabstrip.Add()
                   .Text("Maintenance")
                   .Content(() =>
                   {
                       Html.Telerik().Grid<WiseLink.RDS.Model.MaintenanceModel>()
                              .Name("VehicleMaintenance")
                              .Columns(columns =>
                              {
                                  columns.Bound(f => f.MaintenanceTypeName).Width(50);
                                  columns.Bound(f => f.ServiceMileage).Width(200);
                                  columns.Bound(f => f.ServicePeriod).Width(200);
                                  columns.Bound(f => f.LastServiceDate).Format("{0:MM/dd/yyyy}").Width(120);
                                  columns.Bound(f => f.LastServiceMileage).Width(100);
                              })
                              .DataBinding(dataBinding => dataBinding.Ajax().Select("GetMaintenanceByVehicle", "Diagnostic"))
                              .ClientEvents(clientEvents => clientEvents.OnDataBinding("onDataBinding"))
                              .Pageable()
                              .Sortable()
                              .Render();
                   });

                tabstrip.Add()
                   .Text("ContactRecord")
                   .Content(() =>
                   {
                       Html.Telerik().Grid<WiseLink.RDS.Model.PhoneContactModel>()
                              .Name("VehicleContactRecord")
                              .Columns(columns =>
                              {
                                  columns.Bound(f => f.Operator).Width(50);
                                  columns.Bound(f => f.ContactTime).Format("{0:MM/dd/yyyy}").Width(120);
                                  columns.Bound(f => f.ContactResult).Width(100);
                                  columns.Bound(f => f.Remark).Width(200);
                              })
                              .DataBinding(dataBinding => dataBinding.Ajax().Select("GetPhoneContactHistoryByVehicle", "Diagnostic"))
                              .ClientEvents(clientEvents => clientEvents.OnDataBinding("onDataBinding"))
                              .Pageable()
                              .Sortable()
                              .Render();
                   });
            })
            .ClientEvents(events => events.OnSelect("OnTabSelected"))
            .Render();
        %>
                                

    <script type="text/javascript">
        var vehicleID;
        var tabItemText;
        function onSaveContact(e) {
            $.post("Diagnostic/AddContactHistoryForVehicle",
                    "vehicleID=" + vehicleID + "&contactResult=" + $("#contactResultList").data("tDropDownList").value() + "&contactRemark=" + $("#contactRemark")[0].value,
                    "json")
            .error(function () { alert("error"); })
            
        }
        function OnTabSelected(e) {
            var item = $(e.item);
            tabItemText = item.find('> .t-link').text();
            $('#tabItemText').text(tabItemText);
            refreshTabGrid();
        }
        function refreshTabGrid() {
            if ((tabItemText == null) || (isNaN(vehicleID))) return;
            var currentGrid;
            switch (tabItemText) {
                case 'Fault':
                    currentGrid = $('#VehicleFault').data('tGrid');
                    break;
                case 'Maintenance':
                    currentGrid = $('#VehicleMaintenance').data('tGrid');
                    break;
                case 'ContactRecord':
                    currentGrid = $('#VehicleContactRecord').data('tGrid');
                    break;
                default:
                    alert("Wrong tab " + tabItemText);
            };
            currentGrid.rebind();
        }
        function onRowSelected(e) {
            vehicleID = e.row.cells[5].innerHTML;
            if (vehicleID == "") {
                vehicleID = 0;
            }
            $('#vehicleID').text(vehicleID);
            refreshTabGrid();
            
        }
        function onDataBinding(e) {
            
            e.data = $.extend(e.data, { VehicleID: vehicleID });
        }
     </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
